package com.study.chat.controller;

import com.study.chat.controller.dto.ChatDto;
import com.study.chat.support.Responder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/chat")
public class ChatController {
    @Autowired
    private Responder responder;

    @PostMapping
    public String chat(@RequestBody ChatDto chatDto){
        String input = chatDto.getMsg();
        try {
            String response = responder.doResponse(input);
            return response;
        } catch (Exception exception) {
            exception.printStackTrace();
            return "网络情况差，请重试";
        }
    };
}
